// DlgFilter.cpp : implementation file
//

#include "stdafx.h"
#include "PhotoEdit.h"
#include "DlgFilter.h"
#include "afxdialogex.h"


// CDlgFilter dialog

IMPLEMENT_DYNAMIC(CDlgFilter, CDialogEx)

CDlgFilter::CDlgFilter(CWnd* pParent /*=NULL*/)
	: CDialogEx(CDlgFilter::IDD, pParent)
{

}
CDlgFilter::CDlgFilter(CDlgHomeTab* pParent)
	: CDialogEx(CDlgFilter::IDD, pParent)
{
	m_pHomeTab = pParent;
	
}
CDlgFilter::~CDlgFilter()
{

}

void CDlgFilter::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_SLIDER_BLUR, m_ctrSliderBlur);
	DDX_Control(pDX, IDC_SLIDER_EDGE, m_ctrSliderEdge);
	DDX_Control(pDX, IDC_CHECK_BLUR, m_ctrCheckBlur);
	DDX_Control(pDX, IDC_CHECK_EDGE, m_ctrCheckEdge);
}

BOOL CDlgFilter::OnInitDialog()
{
	CDialogEx::OnInitDialog();
	m_pHomeTab->m_pPhoto->CreateBackup();
	m_pHomeTab->m_pPhoto->BeginComplex();
	m_ctrSliderBlur.SetRange(1,9);
	m_ctrSliderBlur.SetPos(2);
	m_ctrSliderEdge.SetRange(20,500);
	m_ctrSliderEdge.SetPos(100);

	m_ctrCheckBlur.SetCheck(TRUE);
	m_ctrCheckEdge.SetCheck(TRUE);
	Apply();
	return TRUE; 
}


BEGIN_MESSAGE_MAP(CDlgFilter, CDialogEx)
//	ON_NOTIFY(NM_CUSTOMDRAW, IDC_SLIDER_BLUR, &CDlgFilter::OnNMCustomdrawSliderBlur)
	ON_BN_CLICKED(IDC_CHECK_BLUR, &CDlgFilter::OnBnClickedCheckBlur)
	ON_BN_CLICKED(IDC_CHECK_EDGE, &CDlgFilter::OnBnClickedCheckEdge)
	ON_WM_HSCROLL()
	ON_BN_CLICKED(IDCANCEL, &CDlgFilter::OnBnClickedCancel)
	ON_BN_CLICKED(IDOK, &CDlgFilter::OnBnClickedOk)
END_MESSAGE_MAP()

void CDlgFilter::Apply()
{
	m_pHomeTab->m_pPhoto->RetoreBackup(false);
	if(m_ctrCheckBlur.GetCheck())
	{
		m_pHomeTab->m_pPhoto->Blur(m_ctrSliderBlur.GetPos()*2+1);
	}
	if(m_ctrCheckEdge.GetCheck())
	{
		m_pHomeTab->m_pPhoto->EdgeDetect(m_ctrSliderEdge.GetPos());
	}
	m_pHomeTab->RefreshDraw();
}

void CDlgFilter::OnBnClickedCheckBlur()
{
	// TODO: Add your control notification handler code here
	Apply();
}

void CDlgFilter::OnBnClickedCheckEdge()
{
	// TODO: Add your control notification handler code here
	Apply();
}

void CDlgFilter::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
	Apply();
	CDialogEx::OnHScroll(nSBCode, nPos, pScrollBar);

}


void CDlgFilter::OnBnClickedCancel()
{
	// TODO: Add your control notification handler code here
	m_pHomeTab->m_pPhoto->EndComplex();
	m_pHomeTab->m_pPhoto->RetoreBackup(true);
	m_pHomeTab->RefreshDraw();
	CDialogEx::OnCancel();
}


void CDlgFilter::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	m_pHomeTab->m_pPhoto->EndComplex();
	CDialogEx::OnOK();
}
